package com.cbb.display.config.quartz.job;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import com.cbb.display.entity.TodayUserConfig;
import com.cbb.display.service.TodayUserConfigService;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.cbb.display.entity.TodayData;
import com.cbb.display.entity.TotalData;
import com.cbb.display.service.TodayDataService;
import com.cbb.display.service.TotalDataService;
import com.cbb.display.util.RandomUtil;

/** 

* @author 作者 lujunjie: 

* @version 创建时间：Jan 18, 2020 2:54:35 PM 

* 类说明 

*/
@Component
public class TodayJobUserOrder implements Job{
	@Autowired
	private TodayDataService todayDataService;
	@Autowired
	private TotalDataService totalDataService;
	@Autowired
	private TodayUserConfigService todayUserConfigService;
  @Override
  public void execute(JobExecutionContext arg0) throws JobExecutionException {
	  BigDecimal randomOrderAmount = new BigDecimal(0);
	  TodayUserConfig todayUserConfig = todayUserConfigService.getOne(null);
	  int randomUser= RandomUtil.UserPercentageRandom(todayUserConfig);
	  int randomOrder= RandomUtil.OrderPercentageRandom();
	  String orderfrom = RandomUtil.OrderFromRandom();
	  if(randomOrder>0)
	  {
		  randomOrderAmount= RandomUtil.getOrderAmountRandom(10000.00,50000.00);
	  }
	  LocalDateTime localDateTime= LocalDateTime.now();
	  localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
	  TodayData todayData = TodayData.builder()
			  .todayadduser(randomUser)
			  .todayplaceorder(randomOrder)
			  .todayplaceorderamount(randomOrderAmount)
			  .createmonth(localDateTime.getMonth().getValue())
			  .orderfrom(orderfrom)
              .createDate(localDateTime).build();
    //你的业务逻辑
	 System.out.println("今天的数据为"+todayData.toString());
	 TotalData totalData = TotalData.builder()
			 .usernums(randomUser)
			 .orderfinishednums(randomOrder)
			 .orderfinishedamount(randomOrderAmount)
			 .build();
	 totalDataService.saveTotal(totalData);
	 todayDataService.save(todayData);
	 
  }
}
